package Game.Objects.Creatures;

import java.lang.reflect.InvocationTargetException;
import java.util.Random;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import Game.GameHelper;
import Game.Items.GameItem;
import Game.Items.Armors.Helmets.GIRustyHelmet;
import Game.Items.Craft.GIApple;
import Game.Items.Craft.GIBone;
import Game.Items.Craft.GICarrot;
import Game.Items.Craft.GIPotato;
import Game.Items.Craft.GISteelIngot;
import Game.Items.Others.GITorch;
import Game.Items.Potions.GISmallHealthPotion;
import Game.Items.Weapons.GIRustySword;
import Game.Items.Weapons.GIWoodClub;
import Game.MapBlock.EMapBlockType;
import Game.Objects.GOPlayer;
import Game.Objects.GameObject;
import Game.Objects.ObjectManager;
import GameMath.GPoint;
import GameMath.GSize;

/** Civilian class
 * @author Aikidos
 */
public class GOCCivilian extends GOCreature {

	public GOCCivilian(ObjectManager objectManager) throws SlickException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
		super(objectManager, "Civilian");
		
		setSprite(new Image("res/gfx/creatures/civilian.png"));
		
		Type = EGameObjectType.Ally;
		
		MaxHealth = 25;
		setHealth(MaxHealth);
		
		// Set default damage
		MinDamage = 1;
		MaxDamage = 2;
	}

	@Override
	public void step() throws SlickException {
		super.step();
		
		// Else go to random coordinate
		if (getWalkPath().size() == 0) {
			stepGoToRandomCoord();
		}
		
		walk();
	}

	@Override
	public boolean onCollision(GameObject other, boolean moveOn) {
		
		
		return true;
	}
	
	private void stepGoToRandomCoord() {
		// Get map size
		GSize mapSize = _objectManager.getLevel().getMap().getSize();

		// Go to random coordinates
		Random rnd = GameHelper.getRandom();

		GPoint p = new GPoint(rnd.nextInt(mapSize.width),
				rnd.nextInt(mapSize.height));

		while (_objectManager.getLevel().getMap().getBlocks()[p.x][p.y].Type != EMapBlockType.Floor)
			p = new GPoint(rnd.nextInt(mapSize.width),
					rnd.nextInt(mapSize.height));

		go(p);
	}
}
